package com.jerry.hm.design.pattern.principle.demo2.before;

/**
 * RectangleDemo
 *
 * @author Jerry
 * @since 2025/8/30 15:12
 */
public class RectangleDemo {

    public static void main(String[] args) {
        Rectangle rectangle = new Rectangle();
        rectangle.setLength(20);
        rectangle.setWidth(10);
        resize(rectangle);
        printLengthAndWidth(rectangle);

        Square square = new Square();
        square.setLength(10);
        resize(square);
        printLengthAndWidth(square);
    }

    private static void resize(Rectangle rectangle) {
        // 如果宽比长小，则将宽设置为长
        while (rectangle.getWidth() <= rectangle.getLength()) {
            rectangle.setWidth(rectangle.getWidth() + 1);
        }
    }

    public static void printLengthAndWidth(Rectangle rectangle) {
        System.out.println("长：" + rectangle.getLength());
        System.out.println("宽：" + rectangle.getWidth());
    }
}
